package com.ldg.manager.controller;


import com.ld.utils.FastDFSClient;
import com.ld.pojo.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {


	@PostMapping("upload")
	public R upload(MultipartFile file) throws Exception {
		//获得文件名字
		String filename = file.getOriginalFilename();
		//获得文件后缀名
		String suffix = filename.substring(filename.lastIndexOf(".") + 1);
		//构建fastdfs客户端对象
		FastDFSClient client = new FastDFSClient("classpath:fastdfs.conf");
		//文件上传
		String s = client.uploadFile(file.getBytes(), suffix);
		//拼接url
		String url = "http://192.168.56.110:8080/" + s;
		return R.ok().put("url",url);
	}
}
